﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using HistogramControlTest.Controls;

namespace HistogramControlTest
{
    public partial class MainPage : UserControl
    {
        public MainPage()
        {
            InitializeComponent();

            Init();
        }

        private void Init()
        {
            Random r = new Random();
            HistogramControl histogram;

            histogram = new HistogramControl(ShowFormat.Normal, 1.0)
            {
                Margin = new Thickness(20, 0, 20, 0),
                Value = 20,
                Text = "柱状图-1",
                IsOperable = true
            };
            histogram.HistogramChecked += Onhistogram_Checked;
            XsPanel.Children.Add(histogram);
            histogram = new HistogramControl(ShowFormat.Normal, 1.0)
            {
                Margin = new Thickness(20, 0, 20, 0),
                Value = 40,
                Text = "柱状图-2",
                IsOperable = true
            };
            histogram.HistogramChecked += Onhistogram_Checked;
            XsPanel.Children.Add(histogram);
            histogram = new HistogramControl(ShowFormat.Normal, 1.0)
            {
                Margin = new Thickness(20, 0, 20, 0),
                Value = 60,
                Text = "柱状图-3",
                IsOperable = true
            };
            histogram.HistogramChecked += Onhistogram_Checked;
            XsPanel.Children.Add(histogram);
            histogram = new HistogramControl(ShowFormat.Normal, 1.0)
            {
                Margin = new Thickness(20, 0, 20, 0),
                Value = 80,
                Text = "柱状图-4",
                IsOperable = true
            };
            histogram.HistogramChecked += Onhistogram_Checked;
            XsPanel.Children.Add(histogram);
            histogram = new HistogramControl(ShowFormat.Normal, 1.0)
            {
                Margin = new Thickness(20, 0, 20, 0),
                Value = 100,
                Text = "柱状图-5",
                IsOperable = true
            };
            histogram.HistogramChecked += Onhistogram_Checked;
            XsPanel.Children.Add(histogram);


            for (int i = 0; i < 10; i++)
            {
                int m = i * 10;
                histogram = new HistogramControl(ShowFormat.Normal, 1.0)
                {
                    Margin = new Thickness(10, 0, 10, 0),
                    Value = m,
                    Text = "qwe",
                    IsShowText = false,
                    IsOperable = true,
                    RectBackground = new SolidColorBrush(Color.FromArgb(255, 252, 189, 145))
                };
                XsPanel1.Children.Add(histogram);
            }

            for (int i = 0; i < 100; i++)
            {
                int d = r.Next(100);
                histogram = new HistogramControl(ShowFormat.Normal, 1.0)
                {
                    Value = d,
                    Text = d.ToString(),
                    IsShowText = false,
                    IsOperable = false,
                    IsWide = false,
                    IsShowTop = false,
                    RectBackground = new SolidColorBrush(Color.FromArgb(255, 200, 72, 00))
                };
                XHisGroup1.AddItem(histogram);
            }
            XHisGroup1.Text = "柱状图-Group1";
        }

        void Onhistogram_Checked(HistogramControl obj)
        {
            foreach (var ui in XsPanel.Children)
            {
                HistogramControl ctrl = ui as HistogramControl;
                if (ctrl != null)
                    ctrl.IsChecked = ctrl == obj;
            }
        }

        private void XChkBox_Click(object sender, RoutedEventArgs e)
        {
            bool flag = ((CheckBox) sender).IsChecked.GetValueOrDefault();

            foreach (var item in XsPanel.Children)
            {
                ((HistogramControl) item).IsShowText = flag;
            }
        }
    }
}
